﻿using System;
using System.Text;

namespace MINERP.COM.DBHelper {
	/// <summary>The conn str protector.</summary>
	public class ConnStrProtector {
		/// <summary>The decrypt db connection string.</summary>
		/// <param name="inputConnectionString">The input connection string.</param>
		/// <returns>The decrypt db connection string.</returns>
		public static string DecryptDBConnectionString(string inputConnectionString) {
			if (inputConnectionString.Equals(string.Empty)) {
				return inputConnectionString;
			}
			byte[] bytes = new DataProtector(Store.Machine).Decrypt(Convert.FromBase64String(inputConnectionString), null);
			return Encoding.ASCII.GetString(bytes);
		}
		/// <summary>The encrypt db connection string.</summary>
		/// <param name="inputConnectionString">The input connection string.</param>
		/// <returns>The encrypt db connection string.</returns>
		public static string EncryptDBConnectionString(string inputConnectionString) {
			DataProtector protector = new DataProtector(Store.Machine);
			byte[] bytes = Encoding.ASCII.GetBytes(inputConnectionString);
			return Convert.ToBase64String(protector.Encrypt(bytes, null));
		}
	}
}
